#include<bits/stdc++.h>
#define ll long long 
const int mod = 998244353;
using namespace std;

//判断是否是素数
bool is_prime(int n)
{
	if (n < 2)return false;
	for (int i = 2; i * i <= n; i++)
		if (n % i == 0)return false;

	return true;
}

//求阶乘
ll fact(ll x)
{
	ll ret = 1;   
	for (int i = 1; i <= x; i++)
	{
		ret = ret % mod * i % mod;
		ret%=mod;   
	}
	return ret;
}

int prime_num(int n)
{
	int cnt = 0;
	for (int i = 2; i <= n; i++)
		if (is_prime(i))cnt++;
	return cnt;
}

int main()
{
	int t = 0; cin >> t;
	while (t--)
	{
		ll n; cin >> n;
		ll cnt = prime_num(n);//统计2-n素数的个数  
		ll nocnt = n - cnt - 1;//不是素数的个数n-1-cnt       
		//第一种情况
		ll ret1 = 2 % mod * nocnt % mod * fact(n - 2) % mod;
		ret1 %= mod;
		//cout << ret1 << endl; 
		ll ret2 = 0;

		if (nocnt > 1)
		{
			ret2 = nocnt % mod * (nocnt - 1) % mod * fact(n - 2) % mod;
			ret2 %= mod;
		}
		//第二种情况
		ll ret = ret1 % mod + ret2 % mod;
		ret %= mod;
		cout << ret ;
        if(t)cout<<endl; 
	}
    return 0;
}

